<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改问题库')" />
</head>
<body class="white-bg">
<div class="btn-group-sm" id="toolbar" role="group">
    <a class="btn btn-primary  " onclick="selectRelative()">
        <i class="fa fa-edit"></i> 新增加相关问题
    </a>
</div>

    <div class="wrapper wrapper-content animated fadeInRight ibox-content">

        <form class="form-horizontal m" id="form-knowkedg-edit" th:object="${qKnowkedg}">
            <input name="knowledgId" th:field="*{knowledgId}" type="hidden">
            <div class="form-group">
                <label class="col-sm-3 control-label">用户问题：</label>
                <div class="col-sm-8">
                    <textarea name="question" class="form-control">[[*{question}]]</textarea>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答案1：</label>
                <div class="col-sm-8">
                    <input name="answer1" th:field="*{answer1}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答案2：</label>
                <div class="col-sm-8">
                    <input name="answer2" th:field="*{answer2}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">答案3：</label>
                <div class="col-sm-8">
                    <input name="answer3" th:field="*{answer3}" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>

    <div>
        <h4>已存在相关问题列表</h4>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>

    <th:block th:include="include :: footer" />

    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:knowkedg:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:knowkedg:remove')}]];
        var prefix = ctx + "system/knowkedg";
        var deleteFxqueston = function (knowledgId){

            var mainId = $('#knowledgId').val();

            $.ajax({
                url:"/system/knowkedg/deleteFxqueston",
                data:{"knowledgId":mainId,  "relativeId": knowledgId },
                type:"POST",
                success:function (data) {


                   $.table.refresh();


                },
                dataType : "json"
            });
        };




        $(function () {


            
            var knowledgId = $('#knowledgId').val();

            var options = {
                url: prefix + "/listxgwt/"+knowledgId,
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/removexgwt",
                exportUrl: prefix + "/export",
                importUrl: prefix + "/importData",
                importTemplateUrl: prefix + "/importTemplate",
                modalName: "问题库",
                columns: [{
                    checkbox: true
                },
                    {
                        field: 'knowledgId',
                        title: '已有的知识id',
                        visible: true
                    },
                    {
                        field: 'type',
                        title: '类别'
                    },
                    {
                        field: 'question',
                        title: '已有的相关问题名称'

                    },
                    {
                        title: '操作',
                        align: 'center',
                        formatter: function (value, row, index) {
                            var actions = [];
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="deleteFxqueston(\'' + row.knowledgId + '\')"><i class="fa fa-remove"></i>删除相关问题</a>');
                            return actions.join('');
                        }
                    }]
            };
            $.table.init(options);
        });
    </script>

    <script th:inline="javascript">

        /* 弹窗问题 */
        function selectRelative() {
            var knowledgId = $('#knowledgId').val();
            var url = ctx + 'system/knowkedg/selectRelative/' + knowledgId;
            $.modal.open("增加相关问题", url, '770', '580');
        }


        var prefix = ctx + "system/knowkedg";
        $("#form-knowkedg-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-knowkedg-edit').serialize());
            }
        }
    </script>
</body>
</html>